package com.zc.serveudpdemo.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.zc.serveudpdemo.UsbConnectStatus;
import com.zc.serveudpdemo.callback.DeviceObserver;
import com.zc.serveudpdemo.utils.FiFoUsbStream;

/**
 * 功能描述：所有activity继承此类
 *
 * @author：ZC 创建时间：2019/5/28 9:29
 * 最后修改日期：
 */
public abstract class BaseActivity extends AppCompatActivity implements DeviceObserver {

    private Context mContext = null;
    protected UsbConnectStatus mUsbConnectStatus = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        //去除头部
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //去除状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        if (mUsbConnectStatus == null) {
            mUsbConnectStatus = new UsbConnectStatus(mContext);
            mUsbConnectStatus.addDataObserver(this);
        }
        init(savedInstanceState);
    }

    /**
     * @param savedInstanceState
     * @return void
     * @description: 主要用于控件等初始化工作
     */
    protected abstract void init(Bundle savedInstanceState);

    @Override
    public void onUsbStream(FiFoUsbStream fiFoUsbStream) {
        revUsbStreamData(fiFoUsbStream);
    }

    protected void revUsbStreamData(FiFoUsbStream fiFoUsbStream) {

    }

    protected void startSaveH264() {
        if (mUsbConnectStatus != null) {
            mUsbConnectStatus.startSave();
        }
    }

    protected void stopSaveH264() {
        if (mUsbConnectStatus != null) {
            mUsbConnectStatus.stopSave();
        }
    }


    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        if (mUsbConnectStatus != null) {
            mUsbConnectStatus.removeObserver(this);
        }
        if (mUsbConnectStatus != null) {
            mUsbConnectStatus.destroy();
        }
        super.onDestroy();
    }
}
